package com.example.leetdemo.process;

import org.springframework.util.StringUtils;

import java.util.Arrays;

public class Solution3297 {

    public long validSubstringCount(String word1, String word2) {
        long count = 0;
        char[] word2Arr = word2.toCharArray();
        Arrays.sort(word2Arr);
        word2 = String.copyValueOf(word2Arr);
        for (int i = 0; i < word1.length() - word2.length(); i++) {
            char[] temp = word1.substring(i, i + word2.length()).toCharArray();
            Arrays.sort(temp);
            if (word2.equals(String.copyValueOf(temp))) {
                count += word1.length() - word2.length() - i + 1;
            }
        }
        return count;
    }

}
